/***************************************************************************
 *   Copyright (C) 2008 by Eduardo Gurgel Pinho                            *
 *   edgurgel@gmail.com                                                    *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 3 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
***************************************************************************/

#ifndef __OBJECT_H__
#define __OBJECT_H__

#include "material/object_material.h"
#include "material/texture_material.h"
#include "material/color_material.h"
#include "math/vector.h"
#include "math/ray.h"

#include <boost/tuple/tuple.hpp>
#include <boost/serialization/is_abstract.hpp>
#include <boost/serialization/nvp.hpp>
#include <vector>

using namespace boost::tuples;

namespace Sirat {

namespace Object {

/**
 * Object class.
 */
	
class Object {
public:
	
	/**
	 * Virtual destructor.
	 */
	virtual ~Object();
	
	/**
	 * Main function.
	 * @param _ray 
	 * @return Intersection point and the distance from ray's origin.
	 */
	virtual	tuple<double,Math::Vector,Object*> intersection(const Math::Ray& _ray) = 0;
	
	/**
	 * Normal vector at any given point.
	 * @param _point
	 * @return Object's normal vector.
	 */
	virtual Math::Vector get_normal(const Math::Vector& _point) const = 0;
	
	/* It will be pure virtual (one day) */
	
	virtual tuple<double,double> get_u_v(const Math::Vector&) const { return make_tuple(0.0,0.0); }
	
	/**
	 * @return Current material.
	 */
	Material::Object_Material* get_material();
	
	/**
	 * Change material.
	 * @param _material
	 */
	void set_material(Material::Object_Material* _object_material);

	virtual bool is_limitable() const { return false; }

	virtual bool is_set() const { return false; }

	virtual const std::vector<Object*> get_object_list() const {
		std::vector<Object*> result;
		result.push_back((Object*) this);
		return result;
	}

	virtual Math::Vector get_min_point() const { return Math::Vector(0.0,0.0,0.0); }
	virtual Math::Vector get_max_point() const { return Math::Vector(0.0,0.0,0.0); }
	virtual Object* clone() = 0;

protected:
	/**
	 * Simple constructor.
	 * @param _material
	 */
	Object(Material::Object_Material* _material);
	
	/**
	 * Default constructor.
	 * Boost Serialization needs a default constructor
	 * @see Object(const Object&)
	 */
	Object();
	
	/**
	 * Copy constructor.
	 * @param _object 
	 */
	Object(const Object& _object);
	
	Object& operator=(const Object& _object);
	
	Material::Object_Material* object_material;

private:
	friend class boost::serialization::access;
	template<class Archive> void serialize(Archive&, const unsigned int);
};

template<class Archive> void Object::serialize(Archive& ar, const unsigned int /* file_version */){
	ar.register_type(static_cast<Material::Color_Material*>(0));
	ar.register_type(static_cast<Material::Texture_Material*>(0));
	ar & BOOST_SERIALIZATION_NVP(object_material);
}

}

}

BOOST_IS_ABSTRACT(Sirat::Object::Object)

#endif
